package com.feisi.dao;

import com.feisi.dao.sqlProvider.ActivitySqlProvider;
import com.feisi.dao.sqlProvider.UserSqlProvider;
import com.feisi.domain.Activity;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ActivityDao {

    /**
     * 查询所有活动
     *
     * @param page
     * @param limit
     * @return
     */
    @Select("select * from activity limit #{page},#{limit}")
    List<Activity> findAll(@Param("page") Integer page, @Param("limit") Integer limit);

    /**
     * 查询总条数
     *
     * @return
     */
    @Select("select count(*) from activity")
    Integer activityTotal();

    /**
     * 根据名称查询活动
     *
     * @param ac_name
     * @param page
     * @param limit
     * @return
     */
    @Select("select * from activity where ac_name = #{ac_name} limit #{page},#{limit}")
    List<Activity> findByName(@Param("ac_name") String ac_name, @Param("page") Integer page, @Param("limit") Integer limit);

    /**
     * 根据活动名称,查询总条数
     *
     * @return
     */
    @Select("select count(*) from activity where ac_name=#{ac_name}")
    Integer activityTotalByName(@Param("ac_name") String ac_name);


    /**
     * 新建活动
     *
     * @param activity
     */
    @Insert("insert into activity values(#{id},#{ac_name},#{ac_object},#{ac_creator},#{ac_type}," +
            "#{ac_start_time},#{ac_end_time},#{ac_budget},#{ac_site},#{ac_create_time},#{ac_introduction})")
    void saveActivity(Activity activity);

    /**
     * 修改活动
     *
     * @param activity
     */
    @Update("update activity set ac_name=#{ac_name},ac_object=#{ac_object},ac_creator=#{ac_creator},ac_type=#{ac_type}," +
            "ac_start_time=#{ac_start_time},ac_end_time=#{ac_end_time},ac_budget=#{ac_budget},ac_site=#{ac_site},ac_create_time=#{ac_create_time},ac_introduction=#{ac_introduction} where id=#{id}")
    void updateActivity(Activity activity);


    /**
     * 根据id删除活动
     *
     * @param ids
     */
    @DeleteProvider(type = ActivitySqlProvider.class,method = "deleteByIds")
    void deleteActivity(@Param("ids") Integer[] ids);

    /**
     * 根据id删除用户
     * 批量删除
     * @param ids
     */
    @DeleteProvider(type = UserSqlProvider.class,method = "deleteByIds")
    void deleteUser(@Param("ids") Integer[] ids);


}
